﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Worldme.YHChatSDK.Common.Constant;

namespace Worldme.YHChatSDK.Framework.Vo.V1.Req
{
    /// <summary>
    /// 发送消息请求体
    /// </summary>
    public class ApiSendMsgReqV1
    {
        /// <summary>
        /// 接收消息对象ID
        /// 用户: userId
        /// 群: groupId
        /// </summary>
        public string recvId { get; set; }
        /// <summary>
        /// 接收对象类型
        /// 用户: user
        /// 群: group
        /// </summary>
        public string recvType { get; set; }
        /// <summary>
        /// 消息类型，取值如下
        /// text\image\file\markdown
        /// </summary>
        public string contentType { get; set; }
        /// <summary>
        /// 消息对象
        /// </summary>
        public ApiSendContentV1 content { get; set; } = new ApiSendContentV1();

        public class ApiSendContentV1
        {
            /// <summary>
            /// 当消息类型为text、markdown时
            /// </summary>
            public string text { get; set; }
            /// <summary>
            /// 当消息类型为image时
            /// </summary>
            public string imageUrl { get; set; }
            /// <summary>
            /// 当消息类型为file时，有值
            /// </summary>
            public string fileName { get; set; }
            public string fileUrl { get; set; }
            /// <summary>
            /// 消息中包括button
            /// 非必填
            /// </summary>
            public List<ApiSendButtonV1> buttons { get; set; } = new List<ApiSendButtonV1>();
        }

        public class ApiSendButtonV1
        {
            /// <summary>
            /// 按钮上的文字
            /// </summary>
            public string text { get; set; }
            /// <summary>
            /// 1: 跳转URL
            /// 2: 复制
            /// 3: 点击汇报
            /// </summary>
            public int actionType { get; set; }
            /// <summary>
            /// 当actionType为1时使用
            /// 非必填
            /// </summary>
            public string url { get; set; }
            /// <summary>
            /// 当actionType为2时，该值会复制到剪贴板
            /// 当actionType为3时，该值会发送给订阅端
            /// 非必填
            /// </summary>
            public string value { get; set; }
        }

        /// <summary>
        /// 文本消息
        /// </summary>
        /// <param name="recvType">RecvTypeConstant.</param>
        /// <param name="recvId">当为USER时，填用户ID，当为GROUP时，填群ID</param>
        /// <param name="text">消息内容</param>
        /// <returns></returns>
        public ApiSendMsgReqV1 Text(string recvType, string recvId, string text)
        {
            ApiSendMsgReqV1 reqV1 = new ApiSendMsgReqV1();
            reqV1.recvId = recvId;
            reqV1.recvType = recvType;
            reqV1.contentType = ContentTypeConstant.TEXT;
            ApiSendContentV1 contentV1 = new ApiSendContentV1();
            contentV1.text = text;
            reqV1.content = contentV1;
            return reqV1;
        }

        /// <summary>
        /// 图片消息
        /// </summary>
        /// <param name="recvType">RecvTypeConstant.</param>
        /// <param name="recvId">当为USER时，填用户ID，当为GROUP时，填群ID</param>
        /// <param name="imageUrl">图片网络直链</param>
        /// <returns></returns>
        public ApiSendMsgReqV1 Image(string recvType, string recvId, string imageUrl)
        {
            ApiSendMsgReqV1 reqV1 = new ApiSendMsgReqV1();
            reqV1.recvId = recvId;
            reqV1.recvType = recvType;
            reqV1.contentType = ContentTypeConstant.IMAGE;
            ApiSendContentV1 contentV1 = new ApiSendContentV1();
            contentV1.imageUrl = imageUrl;
            reqV1.content = contentV1;
            return reqV1;
        }

        /// <summary>
        /// Markdown消息
        /// </summary>
        /// <param name="recvType">RecvTypeConstant.</param>
        /// <param name="recvId">当为USER时，填用户ID，当为GROUP时，填群ID</param>
        /// <param name="text">md消息内容</param>
        /// <returns></returns>
        public ApiSendMsgReqV1 Markdown(string recvType, string recvId, string text)
        {
            ApiSendMsgReqV1 reqV1 = new ApiSendMsgReqV1();
            reqV1.recvId = recvId;
            reqV1.recvType = recvType;
            reqV1.contentType = ContentTypeConstant.MARKDOWN;
            ApiSendContentV1 contentV1 = new ApiSendContentV1();
            contentV1.text = text;
            reqV1.content = contentV1;
            return reqV1;
        }

        /// <summary>
        /// 文件消息
        /// 该方法只能调用一次，并且与其他类型方法互斥
        /// </summary>
        /// <param name="recvType">RecvTypeConstant.</param>
        /// <param name="recvId">当为USER时，填用户ID，当为GROUP时，填群ID</param>
        /// <param name="fileName">文件名</param>
        /// <param name="fileUrl">文件网络直链</param>
        /// <returns></returns>
        public ApiSendMsgReqV1 File(string recvType, string recvId, string fileName, string fileUrl)
        {
            ApiSendMsgReqV1 reqV1 = new ApiSendMsgReqV1();
            reqV1.recvId = recvId;
            reqV1.recvType = recvType;
            reqV1.contentType = ContentTypeConstant.FILE;
            ApiSendContentV1 contentV1 = new ApiSendContentV1();
            contentV1.fileName = fileName;
            contentV1.fileUrl = fileUrl;
            reqV1.content = contentV1;
            return reqV1;
        }

        /// <summary>
        /// 添加一个按钮
        /// 该方法可多次调用，在类型方法调用之后调用
        /// </summary>
        /// <param name="text">按钮上的文字</param>
        /// <param name="actionType">ButtonActionTypeConstant.</param>
        /// <param name="url">当actionType为JUMP_URL时使用，其他时候传null</param>
        /// <param name="value">当actionType为COPY、REPORT时使用，其他时候传null</param>
        /// <returns></returns>
        public ApiSendMsgReqV1 AddButton(string text, int actionType, string url, string value)
        {
            ApiSendButtonV1 buttonV1 = new ApiSendButtonV1();
            buttonV1.text = text;
            buttonV1.actionType = actionType;
            buttonV1.url = url;
            buttonV1.value = value;
            content.buttons.Add(buttonV1);
            return this;
        }
    }
}
